package com.lxw.manager.cms.controller;

import com.lxw.api.cms.CmsPageControllerApi;
import com.lxw.framework.domain.cms.CmsPage;
import com.lxw.framework.domain.cms.request.QueryPageRequest;
import com.lxw.framework.domain.cms.response.CmsPageResult;
import com.lxw.framework.domain.course.response.CoursePublishResult;
import com.lxw.framework.model.response.CommonCode;
import com.lxw.framework.model.response.QueryResponseResult;
import com.lxw.framework.model.response.QueryResult;
import com.lxw.framework.model.response.ResponseResult;
import com.lxw.manager.cms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 *  CmsPage管理Controller,负责页面增删改查,页面预览,发布等功能
 */
@RestController
@RequestMapping("/cms/page")
public class CmsPageController implements CmsPageControllerApi {

    @Autowired
    private CmsPageService cmsPageService;
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findCmsPages(@PathVariable("page") Integer page,
                                            @PathVariable("size") Integer size, QueryPageRequest queryPageRequest) {
        return cmsPageService.findCmsPages(page,size,queryPageRequest);
    }

    @Override
    @PostMapping("add")
    public CmsPageResult addCmsPage(@RequestBody  CmsPage cmsPage) {
        return cmsPageService.addCmsPage(cmsPage);
    }

    @Override
    @GetMapping("/get/{id}")
    public CmsPageResult findCmsPageById(@PathVariable("id") String id) {
        return cmsPageService.findCmsPageById(id);
    }

    @Override
    @PutMapping("/edit/{id}")
    public CmsPageResult updateCmsPageById(@PathVariable("id") String id,@RequestBody CmsPage cmsPage) {

        return cmsPageService.updateCmsPageById(id,cmsPage);
    }

    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult deleteCmsPageById(@PathVariable("id") String id) {
        return cmsPageService.deleteCmsPageById(id);
    }

    @Override
    @PostMapping("/post/{id}")
    public ResponseResult PostCmsPageById(@PathVariable("id") String id) {
        return cmsPageService.postPage(id);
    }

      @Override
      @PostMapping("/save")
      public CmsPageResult saveCmsPage(@RequestBody CmsPage cmsPage) {
            return cmsPageService.saveCmsPage(cmsPage);
      }

      @Override
      @PostMapping("/postPageQuick")
      public CoursePublishResult postPageQuick(@RequestBody CmsPage cmsPage) {
            return cmsPageService.postPageQuick(cmsPage);
      }
}
